//
// Created by Huiyi on 2021/4/25.
//
#include "module_XExpand.h"

//系统_是否64
bool X_System_SysIs64()
{
    SYSTEM_INFO info;
    GetNativeSystemInfo(&info);
    if(info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64
    || info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)
    {
        return true;
    }
    return false;
}

//取系统类型
int X_System_WIsOs ()
{
#if defined I_OS_MAC
    return X_OS_MACOS;
#elif defined I_OS_ANDROID
    return X_OS_ANDROID;
#elif defined I_OS_WIN
    return X_OS_WINDOWS;
//#elif _WIN32
//    return X_OS_WINDOWS32;
#elif defined I_OS_CYGWIN
    return X_OS_CYGWIN;
#elif defined I_OS_SOLARIS
    return X_OS_SUNOS;
#elif defined I_OS_LINUX
    return X_OS_LINUX;
#elif defined I_OS_FREEBSD
    return X_OS_FREEBSD;
#elif defined I_OS_OPENBSD
    return X_OS_OPENBSD;
#elif defined I_OS_AIX
    return X_OS_AIX;
#else
    return X_OS_NULL;
#endif
    return X_OS_NULL;
}

//处理事件
void X_System_DoEvents()
{
    MSG CurrMsg;
    while (PeekMessage (&CurrMsg, 0, 0, 0, 1)){
        TranslateMessage (&CurrMsg);
        DispatchMessage (&CurrMsg);
    }
}


//取DOS执行结果A
CXTextA X_System_RunCmd (CXTextA cmd,void*func)
{
    FILE* pipe;
    string rets;
    rets.reserve(1024* 4);//初始化定义存放结果的字符串变量
    char buffer [128]; //定义缓冲区
    pipe = _popen ("ipconfig", "r"); //打开管道，并执行命令
    if (!pipe)
    {
        return rets;
    }
    while(!feof(pipe)) {
        if(fgets(buffer, 128, pipe)){ //将管道输出到result中
            if (func != NULL && func != nullptr){
                X_System_RunCmd_res fCmd = (X_System_RunCmd_res)func;
                if(fCmd (buffer)){
                    break;
                }
            }
            rets.append(buffer);
        }
    }
    _pclose(pipe);
    return rets;
}


